package handin07;

import java.util.ArrayList;

public class Member extends AbstractPerson implements IMember {
	
	IMembership membership;
	ArrayList<IActivity> activities;
	String memberid;
	
	public Member(IMembership membership, String name, String street,
			String zip, String city, String memberid) 
	{
		super(name, street,zip, city);
		this.membership = membership;
		this.activities = new ArrayList<IActivity>();
		this.memberid= memberid;
	}

	@Override
	public String getMemberID() 
	{
		return memberid;
	}

	@Override
	public IMembership getMembership() 
	{
		return membership;
	}

	@Override
	public ArrayList<IActivity> getSports() 
	{
		return activities;
	}

	@Override
	public boolean addActivity(IActivity activity) 
	{
		if(isAlreadyActive(activity)){
			return false;
		} else {
			activities.add(activity);
			return true;
		}
	}
	
	private boolean isAlreadyActive(IActivity activity)
	{
		for(IActivity a : activities){
			if (a.equals(activity)){
				return true;
			}
		}		
		return false;
	}

	@Override
	public double getMonthlyFee() {
		double fee = membership.getBaseCost();
		for(IActivity a : activities){
			fee += a.getPrice() * (1.0 - membership.getDiscount());
		}		
		return fee;
	}
	
}
